﻿<!DOCTYPE html>
<!--隐患排查上报管理-非计划隐患上报-->
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

    <style>
        body {
            padding-bottom: 10px;
        }
    </style>
</head>
<body>
    <div id="app" v-cloak class="popupW100">
        <el-form :model="Form" status-icon ref="ruleForm" label-width="100px" size="mini" label-position="right">
            <el-form :inline="true">
                <el-row type="flex" justify="begin">
                    <el-form-item>
                        <el-button type="primary" @click="InputInput('tj')">{{col.btnAdd}}</el-button>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="danger" @click="onDelete">{{col.btnDelete}}</el-button>
                    </el-form-item>
                </el-row>
            </el-form><!--ListItem.tableHeight-->
            <el-table stripe ref="table" :data="ListItem.tableData" :row-key="getRowKeys" border
                      @selection-change="handleSelectionChange" :span-method="objectSpanMethod" row-style="height:10px" style="width: 100%;margin:0 auto;margin-bottom:20px;">
                <el-table-column type="selection"
                                 style="padding-top: 0px;padding-bottom: 0px;"
                                 align="center"
                                 width="55"
                                 :reserve-selection="true">
                </el-table-column>
                <el-table-column prop="Project" :label="RisksManagement.UnPlanReport.Project">
                </el-table-column>
                <el-table-column prop="Region" :formatter="getDicValue" :label="RisksManagement.UnPlanReport.Region">
                </el-table-column>
                <el-table-column prop="Remark" :label="RisksManagement.UnPlanReport.Remark">
                </el-table-column>
                <el-table-column prop="Standard.data" :label="RisksManagement.UnPlanReport.Standard">
                </el-table-column>
                <el-table-column prop="RiskLevel" :formatter="getDicValue" :label="RisksManagement.UnPlanReport.RiskLevel" width="100">
                </el-table-column>
                <el-table-column width="53" prop="update" :label="col.btnUpdate" fixed="right">
                    <template slot-scope="scope">
                        <button type="button" class="elst-bt-xg" @click=InputInput('xg',scope.row.id)>
                            <i class="el-icon-edit"></i>
                        </button>
                    </template>
                </el-table-column>
                <el-table-column width="53" prop="update" :label="col.btnOperate" fixed="right">
                    <template slot-scope="scope">
                        <el-link type="primary"
                                 style="color:#409eff;cursor:pointer;"
                                 @click="ReportInput(scope.row.id,scope.row.Standard.name)">{{col.btnReport}}</el-link>
                    </template>
                </el-table-column>
            </el-table>
            
            
        </el-form>
        <el-dialog :title="dialogTitle" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%" height="80%" top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:95%;width:100%" frameborder="0"></iframe>
        </el-dialog>
        
    </div>
    <script type="text/javascript">
        app = new Vue({
            el: '#app',
            data: {
                //父业传参
                id: '',
                dialogTitle:'非计划隐患上报管理',
                //业务表单内容
                ListItem: ListItem,
                mydata: PersonInChargeTree,
                Region: myTree,
                Form: {
                    id: guidEmpty,
                    InputTable: null,
                },
                spanArr: [],
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //上报，id为父级数据id，name为当前数据编号
                ReportInput: function (id, name) {
                    console.log(id)
                    console.log(name)

                    this.dialogTitle = '上报';
                    DialogShow(this, 'tj', "RiskReportInput.html", id);
                    //this.ListItem.InputUrl = "RiskReportInput.html?id=" + id + "&name=" + name + "&t=" + Date.parse(new Date());
                    //this.ListItem.dialogVisible = true;
                },
                getData: function () {
                    var mythis = this;
                    myAjax("get", mythis, '/api/UnPlanReport/GetList', null, function (response) {
                        console.log("response", response)
                        mythis.Form.InputTable = response.data;
                    }, false);
                },
                //表格数据格式化
                getDicValue: function (row, column, cellValue, index) {
                    switch (column.property) {
                        case "Region":
                            return getTreeValue(this.Region, cellValue)
                            break;
                        case "RiskLevel":
                            return getDicValue('03', cellValue)
                            break;
                        default:
                    }

                },
                //列表选择触发
                handleSelectionChange: function (val) { handleSelectionChange(this, val); },
                //合并行
                objectSpanMethod: function (row, column, rowIndex, columnIndex) {
                    //声明列对象，行对象
                    var columnIndex = row.columnIndex, rowIndex = row.rowIndex
                    //判断需要合并的列
                    if (columnIndex === 0 || columnIndex === 1 || columnIndex === 2 || columnIndex === 3 || columnIndex === 6 ) {
                        //读取当前行的合并数量
                        var _row = this.spanArr[rowIndex];
                        //console.log('输出合并行序列',rowIndex, _row)
                        //如果当前行合并，则对应列为1，否则0（0为不显示）
                        var _col = _row > 0 ? 1 : 0;
                        return [_row, _col]
                    }
                },
                //删除方法(Comm中没有适配的delete方法，故仿写一份)
                onDelete: function () {
                    var mythis = this;
                    var url = '/api/UnPlanReport/DeleteMuti';
                    if (mythis.ListItem.tableMultipleSelection.length == 0) {
                        showMessage(msg.AtLeastOne, 'error')
                        return;
                    }
                    mythis.$confirm(' 是否确认继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(function () {
                        var delIds = [];
                        for (var i = 0; i < mythis.ListItem.tableMultipleSelection.length; i++) {
                            var item = mythis.ListItem.tableMultipleSelection[i];
                            delIds.push(item.id);
                        }
                        myAjax("post", mythis, url, delIds, function (response) {
                            mythis.getData();
                            mythis.ListItem.tableData = mythis.Form.InputTable;
                            mythis.getSpanArr(mythis.ListItem.tableData);
                            showMessage(msg.OperatingOk, "success");
                        });
                    }).catch(function () {
                        showMessage("已取消删除!");
                    });
                },
                //合并行方法
                getSpanArr: function (data) {
                    //生成合并行数据组
                    this.spanArr = [];
                    var spanArr = this.spanArr;
                    //console.log('Begin', this.spanArr);
                    //初始化行号
                    var c = 0;
                    //遍历数据
                    //this.ListItem.tableData.forEach(function (v, i) {
                    data.forEach(function (v, i) {
                        //第一条数据固定
                        if (i === 0) {
                            spanArr.push(1);
                        }
                        else {
                            //如果当前数据跟上一条数据id相同，则合并行数据+1，并且填充0合并行
                            if (v.id === data[i - 1].id) {
                                spanArr[c] += 1;
                                spanArr.push(0);
                            }
                            else {
                                //如果不相同，则重置合并数量，且更改合并行数据组索引
                                spanArr.push(1);
                                c = i;
                            }
                        }
                    })
                    //console.log('End', this.spanArr);
                },
                //Dialog展示
                InputInput: function (val, id) {
                    //DialogShow(this, val, "UnPlanReportEditStandardType.html", id);
                    var url = "../RiskContentEditStandardType.html";
                    if (val == 'tj') {
                        this.ListItem.InputUrl = url + "?api=UnPlanReport&t=" + Date.parse(new Date());
                    } else {
                        this.ListItem.InputUrl = url + "?id=" + id + "&api=UnPlanReport&t=" + Date.parse(new Date());
                    }
                    this.ListItem.dialogVisible = true;


                },
                closeDialog: function () {
                    this.getData();
                    this.ListItem.tableData = this.Form.InputTable;
                },
            },
            mounted: function () {
                //绑定下拉和tree
                //this.StandardType = getDicData('59');
                //获取传值id
                //this.id = getUrlParam("id");
                //读取数据
                this.getData();
                this.ListItem.tableData = this.Form.InputTable;
                //表格合并行
                this.getSpanArr(this.ListItem.tableData);
            }
        });
    </script>
</body>

</html>
